package org.ourgrid.broker.business.schedulerdata.executor;

import java.util.ArrayList;
import java.util.List;

import org.ourgrid.broker.business.schedulerdata.SchedulerData;
import org.ourgrid.broker.response.JobEndedResponseTO;
import org.ourgrid.common.internal.IResponseTO;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class JobEndedExecutor extends AbstractSchedulerDataExecutor {
	
	/**
	 * <JOB_ENDED jobID='int' state='int' interestedID='String'/>
	 */
	public List<IResponseTO> execute(SchedulerData command) {
		
		List<IResponseTO> responses = new ArrayList<IResponseTO>();

		Document logDocFile = super.getXMl(command.getXml());
		
		Element element = logDocFile.getDocumentElement();
		
		int jobID = Integer.valueOf(element.getAttribute("jobID"));
		int state = Integer.valueOf(element.getAttribute("state"));
		String interestedID = element.getAttribute("interestedID");
		
		JobEndedResponseTO to = new JobEndedResponseTO();
		to.setInterestedID(interestedID);
		to.setJobID(jobID);
		to.setState(state);

		responses.add(to);
		
		return responses;
	}
}
